﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NeuroAPI
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();

            p.ServerFinden();

            p.NetzLaden(@"C:\netze\netz.nn_net");

            float[] INP = new float[] {0,0,0 };
            float[] OUT = p.NetzBefragen(INP);
        }



        private System.Runtime.Remoting.Channels.Tcp.TcpClientChannel channel;
        private IVisual.I_Controller _ctrl;
        private string IP;

        public void ServerFinden()
        {
            IVisual._SC.frm_Connect _frm_con = new IVisual._SC.frm_Connect();
            if (_frm_con.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                CONNECT(_frm_con.IP.ToString(), _frm_con.Port);
        }

        public void NetzLaden(string NN_NET_File)
        {
            this._ctrl.LOAD_NET(NN_NET_File.Substring(0, NN_NET_File.Length - 4));//_NET abschneiden
        }

        /// <summary>
        /// Stellt die Verbindung zu einer IP und Port her
        /// </summary>
        /// <param name="IP">Ziel-IP</param>
        /// <param name="port">Ziel-Port</param>
        public void CONNECT(string IP, long port)
        {
            channel = new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel();
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, true);

            _ctrl = (IVisual.I_Controller)Activator.GetObject
            (
                typeof(IVisual.I_Controller),
                "tcp://" + IP + ":" + port + "/_RM_Neuro_Controller"
            );

            this.IP = IP;
        }

        public float[] NetzBefragen(float[] _INP)
        {
            return this._ctrl.Compute(_INP);
        }
    }
}
